<template>
  <el-dialog
    title="查看公告"
    :close-on-press-escape="false"
    :close-on-click-modal="false"
    :visible.sync="visible"
    class="jsbos-dialog jsbos-dialog_center jsbos-dialog-notice"
    lock-scroll
    width="60%"
  >
    <div class="notice-wrapper" v-loading="loading">
      <h1 class="title">{{ dataForm.title }}</h1>
      <div class="info">
        <span>{{ jsbos.dateFormat(dataForm.lastModifyTime) }}</span
        ><span>{{ dataForm.creatorUser }}</span>
      </div>
      <div class="main ql-editor" v-html="dataForm.bodyText"></div>
      <div class="file-list" v-if="files.length">
        <UploadFz v-model="files" disabled detailed />
      </div>
    </div>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">{{
        $t("common.cancelButton")
      }}</el-button>
    </span>
  </el-dialog>
</template>

<script>
import "quill/dist/quill.snow.css";
import "quill/dist/quill.core.css";
import "quill/dist/quill.bubble.css";
import { getNoticeInfo } from "@/api/system/message";

export default {
  data() {
    return {
      visible: false,
      loading: false,
      files: [],
      dataForm: {
        id: "",
        title: "",
        creatorUser: "",
        creatorTime: Number,
        bodyText: "",
      },
    };
  },
  methods: {
    init(id) {
      this.dataForm.id = id;
      this.dataForm.bodyText = "";
      this.visible = true;
      this.loading = true;
      this.$nextTick(() => {
        getNoticeInfo(this.dataForm.id)
          .then((res) => {
            this.dataForm = res.data || {};
            this.files = res.data.files ? JSON.parse(res.data.files) : [];
            this.loading = false;
          })
          .catch(() => {
            this.loading = false;
          });
      });
    },
  },
};
</script>
<style lang="scss" scoped>
>>> .el-dialog__body {
  background-color: #eee;
  padding: 10px 0 !important;
}

.notice-wrapper {
  margin: auto;
  width: 768px;
  min-height: 1000px;
  background-color: #fff;
  box-shadow: 5px #cfcfcf;
  padding: 20px;
}
</style>
